package cn.ee.dfs.common.configure;

import cn.ee.dfs.webservice.service.DfsWebService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;
/**
 * Description:
 * Created by TWJ on 2019/10/15 0015 0025 上午 10:46 .
 */
@Configuration
public class CxfWebServiceConfig {
//服务地址为http://127.0.0.1:8080/ws/dfsWebService?wsdl
    @Autowired
    private Bus bus;
    @Autowired
    private DfsWebService helloWebService;

    @Bean("cxfServletRegistration")
    public ServletRegistrationBean dispatcherServlet() {
        //注册servlet 拦截/ws 开头的请求 不设置 默认为：/services/*
        return new ServletRegistrationBean(new CXFServlet(), "/ws/*");
    }

    /*
     * 发布endpoint
     */
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, helloWebService);
//        endpoint.getInInterceptors().add(new AuthInterceptor());//添加校验拦截器
        endpoint.publish("/dfsWebService");//发布地址
        return endpoint;
    }
}
